package com.weizhong.update.receiver;
import com.weizhong.update.R;import com.weizhong.update.util.UpdateDetail;
import android.app.DownloadManager;import android.app.NotificationManager;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.util.Log;import android.view.View;import android.widget.Toast;
public  class DownloadCompleteReceiver extends BroadcastReceiver {	private static final String TAG="DownloadCompleteReceiver";	private int lastDownload=0;	private NotificationManager updateNotificationManager;	private DownloadManager mgr;	private UpdateDetail updateDetail = null;
    @Override    public void onReceive(Context context, Intent intent) {        if(intent.getAction().equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)){        	initNotifiManager(context);        	updateDetail=new UpdateDetail(context);            long downId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);            lastDownload=updateDetail.getDownloadID();            Log.e(TAG," download complete! id : "+downId+";"+updateDetail.getUpdatePath()+"-id:"+lastDownload);            if(downId==lastDownload){            	if (updateDetail.LocalUpdate(context)){            		;            	}else{            		//下载包异常，需要重新下载:    				Intent intent2 = new Intent("com.weizhong.update.update");    				context.sendBroadcast(intent2);            		Toast.makeText(context, R.string.download_packet_error, Toast.LENGTH_LONG).show();            	}
            }
        } 
    }  	/**	  * 初始化	*/	private void initNotifiManager(Context context){	    this.updateNotificationManager = (NotificationManager)context.getSystemService("notification");	    mgr=(DownloadManager)context.getSystemService("download");	}	 /**	 * 删除下载	 * @param view	 */     public void delDownloads(View view,long downId) {         mgr.remove(downId);      }}